import Helper from "../libs/HelperMgr";
import GameManager from "./GameManager";

const { ccclass, property } = cc._decorator;

@ccclass
export default class Gull extends cc.Component {

    private isPrey: boolean = false;
    /**飞翔方向 
     * -1 :向左飞, 
     * 1 :向右飞
    */
    private flyDir: number = 1;
    private flySpeed: number = 10;

    onLoad() {

    }

    start() {
        this.isPrey = false;
        this.flyDir = this.node.x > 0 ? 1 : -1;
    }

    update(dt) {
        if (GameManager.instace.gameIsStart && !GameManager.instace.gameIsOver) {
            if (this.isPrey) {

            } else {
                this.node.scaleX = -this.flyDir;
                this.node.x += this.flyDir * this.flySpeed;
                if (Helper.isOutMap(this.node)) {
                    this.flyDir = -this.flyDir;
                    this.node.y = Helper.randAtoB(600, 900);
                }
            }

        }

    }
}
